<?php
// 将数组转换成查询字符串
function arr2str($arr){
    $str='';
    foreach($arr as $key=>$val){
        $str.=$key.'="'.$val.'",';
    }
    return substr($str,0,-1);
}
// 将相对路径处理成绝对路径
function path($target){
    if(is_string($target)){
        if(substr($target,0,4)==='http'){
            return $target;
        }
        $target='http://'.$_SERVER['HTTP_HOST'].$target;
    }
    return $target;
}
// 获取所有请求头: nginx下直接调用getallheaders会报错
if (!function_exists('getallheaders'))
{
    function getallheaders()
    {
           $headers = [];
       foreach ($_SERVER as $name => $value)
       {
           if (substr($name, 0, 5) == 'HTTP_')
           {
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
           }
       }
       return $headers;
    }
}

// 解析腾讯视频连接地址
// http://vv.video.qq.com/getinfo?vids=c1423qdkt6h&otype=json
// http://vv.video.qq.com/getinfo?vids=c1423qdkt6h&platform=101001&charge=0&otype=json
/*

http://h5vv.video.qq.com/getinfo?vid=y00221a60w7&defn=hd&defnpayver=1&otype=json

http://113.142.51.24/vhot2.qqvideo.tc.qq.com/AMVbhXTgazng5CjtmSpaOI-6cLnQszW3vR6V1myhg5XE/uwMROfz2r57AoaQXGdGnCWddDmbqSGVvgz-kUtE83Gl53mlL/svp_50001/shg_17964372_50001_e9288f1814063433af6e25820d7a2199.f622.mp4?vkey=72090B4A5376866C40D04E6CF5F7D11BCF502EBE4DD4636F9213704F66A456CAEFB31341C5AA96443CB0D57D3FF6E8327662D37FAD657A7895E762A81C05677A827E8C8FC39E2ECDC878878C53BFA032CBA4C5F2423AE679DB662AD26A2F40BF17547015DDDCF1C6284A6C66084327B6


http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400

*/
function parseQQUrl($origin_url){
    $vid=substr($origin_url,-16,11);
    $url="http://vv.video.qq.com/getinfo?vids={$vid}&platform=101001&charge=0&otype=json";
    $jsonp=file_get_contents($url);
    $jsonStr=str_replace("QZOutputJson=",'',substr($jsonp,0,-1));
    $json=json_decode($jsonStr,true)['vl'];
    $url=$json['vi'][0]['ul']['ui'][0]['url'];
    $fn=$json['vi'][0]['fn'];
    $fvkey=$json['vi'][0]['fvkey'];
    $playUrl=$url.$fn.'?vkey='.$fvkey;
    return $playUrl;
}



?>